package 力扣日常刷题.木22二月.第02天207;

import 力扣日常刷题.ListNode;

/**
 * @author 帅小伙
 * @date 2022/2/7
 * @description
 */
public class Demo23两个链表的第一个公共节点 {

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode a = headA;
        ListNode b = headB;
        if(headA == null || headB == null)return null;
        while(a != b) {
            a = a != null ? a.next : headB;
            b = b != null ? b.next : headA;
        }
        return a;
    }

}
